﻿using Password_Manager.Database;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Password_Manager
{
    public partial class Register : Form
    {
        CreateDatabaseAndTables andTables = new CreateDatabaseAndTables();
        public Register()
        {
            InitializeComponent();
            toolTip1.SetToolTip(txtAccount2, "纯数字，长度不超过10位的账号");
            toolTip1.SetToolTip(txtPassword1, "推荐为数字与字母的混合密码，最大支持长度为30");
            toolTip1.AutoPopDelay = 5000; // 提示显示时长（毫秒）
            toolTip1.InitialDelay = 10; // 鼠标悬停后延迟显示（毫秒）
        }

        private void Register_Load(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e) //注册按钮
        {
            string account = txtAccount2.Text.Trim(); // 获取账号输入
            bool isNumeric = long.TryParse(account, out _);

            string password = txtPassword1.Text.Trim(); // 获取密码输入

            string confirmPassword = txtPassword2.Text.Trim(); // 获取确认密码输入

            //支持纯数字，长度不超过10位的账号
            if ( account.Length <= 11 || isNumeric == true)
            {
                if (password == confirmPassword)
                {
                    if(password.Length <= 30)
                    {
                        andTables.UserRegistration(account, password);
                        this.Close(); // 关闭注册窗口
                        return;
                    }
                }
                MessageBox.Show("注册失败！密码不一致！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            MessageBox.Show("注册失败！账号仅支持数字类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button3_Click(object sender, EventArgs e) //退出
        {
            this.Close();
            this.Dispose();
        }

        private void txtPassword1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtPassword2_TextChanged(object sender, EventArgs e)
        {

        }
       
    }
}
